package com.zyl.util;

//	public static final String DATABASE_NAME = "points.db";//数据库名
//	public static final int DATABASE_VERSION = 2;				 //版本
//	public static final String TASK_TABLE = "task";	 //表名


import java.io.IOException;

 

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {

	public static final String DATABASE_NAME = "ag.db";//数据库名
	public static final int DATABASE_VERSION = 1;				 //版本
	public DBHelper(Context context)
	{
		super(context, DATABASE_NAME,null, DATABASE_VERSION);
	}
	
	
	 
	@Override
	public void onCreate(SQLiteDatabase db) {
		
		//账户  account
		//_id
		//name  zyl    robot1
		//money 金钱 
		
		
		//record
		//_id
		//name 是谁买的
		//num 买入的量
		//price 买入的价钱
		//type 买多还是买空  
		//sell 是1否0被卖掉
		//money  盈利多少钱 如果没有被卖掉就是 负的 1000克白银的20%
		//date 买入日期 
		String sql="Create table account(_id integer primary key autoincrement,  name text ,   money integer );";
		db.execSQL(sql); 
		sql="Create table record(_id integer primary key autoincrement,  name text , num integer,price integer, deal integer, type integer, money integer,date integer );";
		db.execSQL(sql); 
		sql="Create table trade(_id integer primary key autoincrement,  name text , num integer,price integer, deal integer, type integer, money integer,date integer );";
		db.execSQL(sql); 
		sql="INSERT INTO account(name,money) VALUES('zyl',10000);";
		db.execSQL(sql); 
		db.execSQL("INSERT INTO trade(name,num,price,type,deal,money,date) VALUES('zyl',0,0,1,1,0,0)"); 
		db.execSQL("INSERT INTO trade(name,num,price,type,deal,money,date) VALUES('zyl',0,0,-1,-1,0,0)"); 
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		
		String sql=" DROP TABLE IF EXISTS account ";
		db.execSQL(sql);
		 sql=" DROP TABLE IF EXISTS record ";
		db.execSQL(sql);
		onCreate(db);
	}
}
